<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>个人组卷</title>
		<link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
		<style type="text/css">
		.group-content{
			margin-top: 20px;
			max-height: 700px;
		}
		.group-content h1{
			text-align:center;
		}
		.group-content table tr td:first-child{
			text-align:center;
		}
		.group-content table tr:first-child{
			height:40px;
			background-color:rgb(242, 242, 242);
			font-size:20px;
			text-align:center;
		}
		.layui-table td, .layui-table th{
			padding: 4px 15px !important;
		}
		.group-content table tr:first-child .layui-icon{
			font-size: 22px !important;
			margin-left: 4px !important;
   			vertical-align: middle !important;
		}
		.group-content table tr td:first-child{
			width:50px;
		}
		.group-content table tr td:last-child{
			width:60%;
		}
		</style>
	</head>
	<body>
		<div class="layui-container group-content">
			<h1>选择要测试的维度</h1>
			<form class="layui-form" action="" id="form1">
  			<table class="layui-table tabdimension" lay-even>
			    <tbody id="tbodydimension">
			    </tbody>
			    <tr style="background-color:#fff">
			        <td colspan="4">
			        	<button id="btncleartab" type="button" class="layui-btn layui-bg-red" style="float: right;margin-left: 20px;">重选</button>
			        	<button id="btnsavepaper" type="button" class="layui-btn layui-bg-blue" style="float: right;">开始测评</button>
			        </td>
			    </tr>
			  </table>
			  </form>
		</div>
		
		<script src="js/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
		layui.use(['form','table'], function(){
			var form = layui.form;
			var table=layui.table;
			
			/* 遮罩层 */
			var indexloaddoc = layer.load(0, {shade: 0.1});
			
			/*维度卷类加载*/
			var dorderi=0;
			$.ajax({
				type : 'get',
				url : 'getallscaletitletype.action',
				datatype : 'json',
				success : function(dimension) {
					if (dimension.code == 0) {
						$("#tbodydimension").html("");
						var atr="<tr><td></td><td>量表维度<i class='layui-icon'>&#xe637;</i></td><td>量表维度描述<i class='layui-icon'>&#xe62a;</i></td></tr>";;
						for(var i = 0; i < dimension.count; i++){
							atr+="<tr><td><input type='checkbox' name='chedimension' value='"+dimension.data[i].dimensionid+"' lay-skin='primary'></td><td>"+dimension.data[i].dimensionName+"</td><td>"+dimension.data[i].dimensionDescribe+"</td></tr>";
						}
						/*
						 var temp = [];
						 for(var i = 0; i < dimension.count; i++){
							if(temp.indexOf(dimension.data[i].dimensionName) == -1){
					            temp.push(dimension.data[i].dimensionName);
					            dorderi+=1;
					            var aradioscal="";
					            for(var j=0;j< dimension.count;j++){
					            	if(dimension.data[i].dimensionid==dimension.data[j].dimensionid){
					            		aradioscal+="<input name='item"+dorderi+"' type='radio' value='"+dimension.data[j].id+"' title='"+dimension.data[j].name+"' />"
					            	}
					            }
					            atr+="<tr><td>"+dimension.data[i].dimensionName+"</td><td>"+aradioscal+"</td></tr>";
							}
						} */
						$("#tbodydimension").append(atr);
						layer.close(indexloaddoc);
						form.render("checkbox");
					}
				},error:function(){layer.alert("维度卷类加载失败！", {icon:2});}
			});
			
			/*点击保存添加试卷*/
			$("#btnsavepaper").click(function(){
				var indexload = layer.load(0, {shade: 0.1});
				var dimensionids="";       //维度id
				/* for(var i=1;i<=dorderi;i++){
	            	var adimensionids=$("input[name='item"+i+"']:checked").val();
	            	if(adimensionids!=null || adimensionids!=undefined){
		  	        	dimensionids+=adimensionids+","; 
	            	}
	            } */
	            $('input[name="chedimension"]:checked').each(function(){ 
	            	dimensionids+=$(this).val()+','; 
	            }); 
				if(dimensionids==null || dimensionids==undefined || dimensionids.length==0){
					layer.msg("至少选择一个维度！",{icon:2});
					return false;
				}
				$.ajax({
        			url: 'addexaminationpaper.action?dimensionid='+dimensionids,  
        	        type: 'get', 
        	        dataType: 'json',  
        	        success: function (getdata) {
        	          if (getdata.code == 10001) {
        	        	  layer.close(indexload);
        	        	  window.location.href="psychTest.jsp?paperName=个人测评&paperDescribe=个人测评&paperid="+getdata.paperid;
        	          }else { 
        	        	  layer.alert(getdata.msg, {icon: 2});
        	          }  
        	        },
        	        error:function(){}
        		});
			});
			
			/*清空form表单*/
			$("#btncleartab").click(function(){
				$("#form1")[0].reset();
			});
		});
		</script>
	</body>
</html>
